﻿package view
{
    import com.core.destroy.*;
    import com.greensock.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import morn.core.components.*;

    public class PowerMove extends Sprite
    {
        private var container:Sprite;
        private var powerSpirte:Sprite;
        private var oldint:Array;
        private var curint:Array;
        private var runing:Boolean = false;
        private var currun:int;
        private var movesp:Sprite;
        private var mMask:Sprite;
        private var powerSpirte1:Sprite;
        private var curIndex:int;

        public function PowerMove(param1:int = 0)
        {
            var _loc_2:Image = null;
            this.oldint = [];
            this.curint = [];
            this.curIndex = param1;
            this.container = new Sprite();
            this.addChild(this.container);
            this.powerSpirte = new Sprite();
            this.addChild(this.powerSpirte);
            this.powerSpirte1 = new Sprite();
            this.addChild(this.powerSpirte1);
            this.mMask = new Sprite();
            this.mMask.graphics.beginFill(16711680, 1);
            this.mMask.graphics.drawRect(0, 0, 50, 23);
            this.mMask.graphics.endFill();
            this.addChild(this.mMask);
            this.movesp = new Sprite();
            var _loc_3:int = 0;
            while (_loc_3 <= 9)
            {
                
                _loc_2 = new Image();
                if (this.curIndex == 2)
                {
                    _loc_2.url = "png.common." + _loc_3;
                }
                else
                {
                    _loc_2.url = "png.common.exp_" + _loc_3;
                }
                _loc_2.y = _loc_3 * 24;
                this.movesp.addChild(_loc_2);
                _loc_3++;
            }
            _loc_3 = 0;
            while (_loc_3 <= 9)
            {
                
                _loc_2 = new Image();
                if (this.curIndex == 2)
                {
                    _loc_2.url = "png.common." + _loc_3;
                }
                else
                {
                    _loc_2.url = "png.common.exp_" + _loc_3;
                }
                _loc_2.y = (_loc_3 + 1) * 24 + 24 * 9;
                this.movesp.addChild(_loc_2);
                _loc_3++;
            }
            this.movesp.mask = this.mMask;
            this.movesp.visible = false;
            this.addChild(this.movesp);
            return;
        }// end function

        public function showPower(param1:int, param2:int, param3:Point = null, param4:Boolean = false) : void
        {
            var _loc_7:int = 0;
            var _loc_9:int = 0;
            var _loc_10:Image = null;
            var _loc_11:int = 0;
            var _loc_5:* = param1.toString();
            var _loc_6:* = Math.abs(param1 - param2).toString();
            if (param4)
            {
                _loc_5 = _loc_5 + "%";
                _loc_6 = _loc_6 + "%";
            }
            this.getpowerAdd(param1, param2, _loc_6, param3);
            DestroyUtil.removeChildren(this.powerSpirte1);
            this.currun = 0;
            this.movesp.y = 0;
            this.movesp.x = 0;
            this.runing = false;
            this.movesp.visible = true;
            this.removeEventListener(Event.ENTER_FRAME, this.enterFramdHandler);
            while (this.oldint.length > 0)
            {
                
                this.oldint.pop();
            }
            while (this.curint.length > 0)
            {
                
                this.curint.pop();
            }
            if (this.powerSpirte.numChildren < 1)
            {
                _loc_7 = 0;
                while (_loc_7 <= (_loc_5.length - 1))
                {
                    
                    _loc_9 = int(_loc_5.substr(_loc_5.length - _loc_7 - 1, 1));
                    _loc_10 = new Image();
                    if (this.curIndex == 2)
                    {
                        _loc_10.url = "png.common." + _loc_9;
                        _loc_10.x = (-_loc_7) * 18;
                    }
                    else
                    {
                        _loc_10.url = "png.common.exp_" + _loc_9;
                        _loc_10.x = (-_loc_7) * 14;
                    }
                    this.powerSpirte.addChild(_loc_10);
                    this.oldint.push(_loc_9);
                    _loc_7++;
                }
            }
            else
            {
                _loc_7 = 0;
                while (_loc_7 <= (_loc_5.length - 1))
                {
                    
                    _loc_11 = int(_loc_5.substr(_loc_5.length - _loc_7 - 1, 1));
                    this.oldint.push(_loc_11);
                    _loc_7++;
                }
            }
            var _loc_8:* = _loc_5.length - 1;
            while (_loc_8 >= 0)
            {
                
                this.curint.push(_loc_5.substr(_loc_8, 1));
                _loc_8 = _loc_8 - 1;
            }
            this.addEventListener(Event.ENTER_FRAME, this.enterFramdHandler);
            return;
        }// end function

        protected function enterFramdHandler(event:Event) : void
        {
            var _loc_2:int = 0;
            var _loc_3:String = null;
            if (this.runing == false)
            {
                this.runing = true;
                if (this.curint.length > this.currun)
                {
                    if (this.powerSpirte.numChildren > this.currun)
                    {
                        this.powerSpirte.removeChildAt(this.currun);
                    }
                    _loc_2 = 0;
                    if (this.oldint.length > this.currun)
                    {
                        _loc_2 = this.oldint[this.currun];
                    }
                    this.movesp.y = 0;
                    _loc_3 = this.curint[this.currun];
                    this.movesp.x = (-this.currun) * 18;
                    this.mMask.x = this.movesp.x;
                    TweenLite.to(this.movesp, 0.5, {y:-24 * 9, onComplete:this.over1});
                }
                else
                {
                    this.removeEventListener(Event.ENTER_FRAME, this.enterFramdHandler);
                    DestroyUtil.removeChildren(this.powerSpirte);
                    this.movesp.visible = false;
                }
            }
            return;
        }// end function

        private function over1() : void
        {
            var _loc_1:Image = null;
            var _loc_2:String = null;
            this.movesp.y = 0;
            if (this.currun < this.curint.length)
            {
                _loc_1 = new Image();
                if (this.curIndex == 2)
                {
                    _loc_2 = "png.common." + this.curint[this.currun];
                    _loc_1.x = (-this.currun) * 18;
                }
                else
                {
                    _loc_2 = "png.common.exp_" + this.curint[this.currun];
                    _loc_1.x = (-this.currun) * 14;
                }
                if (_loc_2 == "png.common.pow2_%")
                {
                    _loc_2 = "png.common.pow2_percent";
                }
                _loc_1.url = _loc_2;
                if (this.powerSpirte1.numChildren > this.currun)
                {
                    this.powerSpirte1.addChildAt(_loc_1, this.currun);
                }
                else
                {
                    this.powerSpirte1.addChild(_loc_1);
                }
                var _loc_3:String = this;
                var _loc_4:* = this.currun + 1;
                _loc_3.currun = _loc_4;
            }
            this.runing = false;
            return;
        }// end function

        private function getpowerAdd(param1:int, param2:int, param3:String, param4:Point) : void
        {
            var _loc_7:Image = null;
            var _loc_8:String = null;
            if (param4 == null)
            {
                return;
            }
            DestroyUtil.removeChildren(this.container);
            var _loc_5:* = new Image();
            if (param1 >= param2)
            {
                _loc_5.url = "png.common.pow2_add";
            }
            else
            {
                _loc_5.url = "png.common.pow2_sub";
            }
            this.container.addChild(_loc_5);
            var _loc_6:int = 0;
            while (_loc_6 < param3.length)
            {
                
                _loc_7 = new Image();
                if (this.curIndex == 2)
                {
                    _loc_8 = "png.common." + param3.substr(_loc_6, 1);
                }
                else
                {
                    _loc_8 = "png.common.exp_" + param3.substr(_loc_6, 1);
                }
                if (_loc_8 == "png.common.pow2_%")
                {
                    _loc_8 = "png.common.pow2_percent";
                }
                _loc_7.url = _loc_8;
                this.container.addChild(_loc_7);
                _loc_7.x = (_loc_6 + 1) * 14;
                _loc_6++;
            }
            this.container.visible = true;
            TweenLite.to(this.container, 1, {x:param4.x, y:param4.y, onComplete:this.onComplete});
            return;
        }// end function

        private function onComplete() : void
        {
            DestroyUtil.removeChildren(this.container);
            this.container.visible = false;
            this.container.x = 0;
            this.container.y = 0;
            return;
        }// end function

    }
}
